\hypertarget{motors_8h}{
\section{atmega1281/mid/include/motors.h File Reference}
\label{motors_8h}\index{atmega1281/mid/include/motors.h@{atmega1281/mid/include/motors.h}}
}
{\ttfamily \#include \char`\"{}structures.h\char`\"{}}\par
{\ttfamily \#include \char`\"{}pwm.h\char`\"{}}\par
{\ttfamily \#include \char`\"{}encoders.h\char`\"{}}\par
\subsection*{Defines}
\begin{DoxyCompactItemize}
\item 
\#define \hyperlink{motors_8h_aa5226d999132effe3c883ffd4e974f47}{TICS\_\-PER\_\-ROT}~362
\item 
\#define \hyperlink{motors_8h_aaa6f04f6f0d7cf1008a53279acf49f07}{WHEEL\_\-RADIUS}~33
\item 
\#define \hyperlink{motors_8h_a598a3330b3c21701223ee0ca14316eca}{PI}~3.14159
\item 
\#define \hyperlink{motors_8h_a85ae9767b23edf40871541d23962784b}{DIR\_\-RIGHT}~4
\item 
\#define \hyperlink{motors_8h_a788d3497514ea05602fd974d7bdcdbde}{DIR\_\-LEFT}~3
\item 
\#define \hyperlink{motors_8h_a9eff471d17bc68f18b14ff75f23aa3bc}{MOTOR\_\-RIGHT}~1
\item 
\#define \hyperlink{motors_8h_a0e2d750df9008232cafa398d2424b778}{MOTOR\_\-LEFT}~0
\item 
\#define \hyperlink{motors_8h_a249e00fdccfe7edf6ebbcf22a17af4ed}{MAX\_\-VEL}~100
\item 
\#define \hyperlink{motors_8h_a6d7874fc65ae0da8c12558b134a0a480}{VEL\_\-FACT}~320
\begin{DoxyCompactList}\small\item\em Relationship between the sample frequency and the max velocity. VEL\_\-FACT =. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
void \hyperlink{motors_8h_a4e438b0560e5f51111b840ec0ae7a470}{motors\_\-getActualVels} (\hyperlink{structvelocities__t}{velocities\_\-t} $\ast$vels, unsigned int sampleFreq)
\begin{DoxyCompactList}\small\item\em Updates the {\ttfamily velocities} structure with the actual velocities of the robots. \item\end{DoxyCompactList}\item 
void \hyperlink{motors_8h_a1669ce1fedb2a775eaac797e0f6a6324}{motors\_\-init} (unsigned char freq)
\begin{DoxyCompactList}\small\item\em Initializes all the hardware used for the motors (encoders and pwm). \item\end{DoxyCompactList}\item 
void \hyperlink{motors_8h_acb966263b9e0b54a8c75e2b4db16afc4}{motors\_\-setVel} (int vel, unsigned char motor)
\begin{DoxyCompactList}\small\item\em Sets the desired velocity for each motor. \item\end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Define Documentation}
\hypertarget{motors_8h_a788d3497514ea05602fd974d7bdcdbde}{
\index{motors.h@{motors.h}!DIR\_\-LEFT@{DIR\_\-LEFT}}
\index{DIR\_\-LEFT@{DIR\_\-LEFT}!motors.h@{motors.h}}
\subsubsection[{DIR\_\-LEFT}]{\setlength{\rightskip}{0pt plus 5cm}\#define DIR\_\-LEFT~3}}
\label{motors_8h_a788d3497514ea05602fd974d7bdcdbde}
\hypertarget{motors_8h_a85ae9767b23edf40871541d23962784b}{
\index{motors.h@{motors.h}!DIR\_\-RIGHT@{DIR\_\-RIGHT}}
\index{DIR\_\-RIGHT@{DIR\_\-RIGHT}!motors.h@{motors.h}}
\subsubsection[{DIR\_\-RIGHT}]{\setlength{\rightskip}{0pt plus 5cm}\#define DIR\_\-RIGHT~4}}
\label{motors_8h_a85ae9767b23edf40871541d23962784b}
\hypertarget{motors_8h_a249e00fdccfe7edf6ebbcf22a17af4ed}{
\index{motors.h@{motors.h}!MAX\_\-VEL@{MAX\_\-VEL}}
\index{MAX\_\-VEL@{MAX\_\-VEL}!motors.h@{motors.h}}
\subsubsection[{MAX\_\-VEL}]{\setlength{\rightskip}{0pt plus 5cm}\#define MAX\_\-VEL~100}}
\label{motors_8h_a249e00fdccfe7edf6ebbcf22a17af4ed}
\hypertarget{motors_8h_a0e2d750df9008232cafa398d2424b778}{
\index{motors.h@{motors.h}!MOTOR\_\-LEFT@{MOTOR\_\-LEFT}}
\index{MOTOR\_\-LEFT@{MOTOR\_\-LEFT}!motors.h@{motors.h}}
\subsubsection[{MOTOR\_\-LEFT}]{\setlength{\rightskip}{0pt plus 5cm}\#define MOTOR\_\-LEFT~0}}
\label{motors_8h_a0e2d750df9008232cafa398d2424b778}
\hypertarget{motors_8h_a9eff471d17bc68f18b14ff75f23aa3bc}{
\index{motors.h@{motors.h}!MOTOR\_\-RIGHT@{MOTOR\_\-RIGHT}}
\index{MOTOR\_\-RIGHT@{MOTOR\_\-RIGHT}!motors.h@{motors.h}}
\subsubsection[{MOTOR\_\-RIGHT}]{\setlength{\rightskip}{0pt plus 5cm}\#define MOTOR\_\-RIGHT~1}}
\label{motors_8h_a9eff471d17bc68f18b14ff75f23aa3bc}
\hypertarget{motors_8h_a598a3330b3c21701223ee0ca14316eca}{
\index{motors.h@{motors.h}!PI@{PI}}
\index{PI@{PI}!motors.h@{motors.h}}
\subsubsection[{PI}]{\setlength{\rightskip}{0pt plus 5cm}\#define PI~3.14159}}
\label{motors_8h_a598a3330b3c21701223ee0ca14316eca}
\hypertarget{motors_8h_aa5226d999132effe3c883ffd4e974f47}{
\index{motors.h@{motors.h}!TICS\_\-PER\_\-ROT@{TICS\_\-PER\_\-ROT}}
\index{TICS\_\-PER\_\-ROT@{TICS\_\-PER\_\-ROT}!motors.h@{motors.h}}
\subsubsection[{TICS\_\-PER\_\-ROT}]{\setlength{\rightskip}{0pt plus 5cm}\#define TICS\_\-PER\_\-ROT~362}}
\label{motors_8h_aa5226d999132effe3c883ffd4e974f47}
\hypertarget{motors_8h_a6d7874fc65ae0da8c12558b134a0a480}{
\index{motors.h@{motors.h}!VEL\_\-FACT@{VEL\_\-FACT}}
\index{VEL\_\-FACT@{VEL\_\-FACT}!motors.h@{motors.h}}
\subsubsection[{VEL\_\-FACT}]{\setlength{\rightskip}{0pt plus 5cm}\#define VEL\_\-FACT~320}}
\label{motors_8h_a6d7874fc65ae0da8c12558b134a0a480}


Relationship between the sample frequency and the max velocity. VEL\_\-FACT =. \hypertarget{motors_8h_aaa6f04f6f0d7cf1008a53279acf49f07}{
\index{motors.h@{motors.h}!WHEEL\_\-RADIUS@{WHEEL\_\-RADIUS}}
\index{WHEEL\_\-RADIUS@{WHEEL\_\-RADIUS}!motors.h@{motors.h}}
\subsubsection[{WHEEL\_\-RADIUS}]{\setlength{\rightskip}{0pt plus 5cm}\#define WHEEL\_\-RADIUS~33}}
\label{motors_8h_aaa6f04f6f0d7cf1008a53279acf49f07}


\subsection{Function Documentation}
\hypertarget{motors_8h_a4e438b0560e5f51111b840ec0ae7a470}{
\index{motors.h@{motors.h}!motors\_\-getActualVels@{motors\_\-getActualVels}}
\index{motors\_\-getActualVels@{motors\_\-getActualVels}!motors.h@{motors.h}}
\subsubsection[{motors\_\-getActualVels}]{\setlength{\rightskip}{0pt plus 5cm}void motors\_\-getActualVels ({\bf velocities\_\-t} $\ast$ {\em vels}, \/  unsigned int {\em sampleFreq})}}
\label{motors_8h_a4e438b0560e5f51111b840ec0ae7a470}


Updates the {\ttfamily velocities} structure with the actual velocities of the robots. The velocities are measured in \% units in respect to the max velocity. The max velocity is dependant on the actual voltage of the battery. The measuring follows the function: \[ vel[%] = sqrt{1} \] 
\begin{DoxyParams}{Parameters}
\item[{\em vels}]The pointer to the {\ttfamily velocities} structure. \item[{\em sampleFreq}]The frequency of the call to this function, in Hz. \end{DoxyParams}
\hypertarget{motors_8h_a1669ce1fedb2a775eaac797e0f6a6324}{
\index{motors.h@{motors.h}!motors\_\-init@{motors\_\-init}}
\index{motors\_\-init@{motors\_\-init}!motors.h@{motors.h}}
\subsubsection[{motors\_\-init}]{\setlength{\rightskip}{0pt plus 5cm}void motors\_\-init (unsigned char {\em freq})}}
\label{motors_8h_a1669ce1fedb2a775eaac797e0f6a6324}


Initializes all the hardware used for the motors (encoders and pwm). Configures the pwm frequency for the motors and starts the odometers. 
\begin{DoxyParams}{Parameters}
\item[{\em vels}]The frequency for pwm. \end{DoxyParams}
\hypertarget{motors_8h_acb966263b9e0b54a8c75e2b4db16afc4}{
\index{motors.h@{motors.h}!motors\_\-setVel@{motors\_\-setVel}}
\index{motors\_\-setVel@{motors\_\-setVel}!motors.h@{motors.h}}
\subsubsection[{motors\_\-setVel}]{\setlength{\rightskip}{0pt plus 5cm}void motors\_\-setVel (int {\em vel}, \/  unsigned char {\em motor})}}
\label{motors_8h_acb966263b9e0b54a8c75e2b4db16afc4}


Sets the desired velocity for each motor. The velocity is defined as a percentage(\%) of the max. velocity, which is dependant on the voltage of the battery. 
\begin{DoxyParams}{Parameters}
\item[{\em vel}]The desired velocity. It is an int betwen 0 and 100. Larger values are truncated to 100. If the parameter is negative, the motor will run backwards. \item[{\em motor}]The selected motor. It has to be one of the following constants: 
\begin{DoxyItemize}
\item MOTOR\_\-LEFT 
\item MOTOR\_\-RIGHT 
\end{DoxyItemize}\end{DoxyParams}
